<template>
	<view>
		<view class="policy" v-for="(item,index) in storeLog" :key="index">
			<view class="policy_top">
				<view class="">{{item.createtime}}</view>
				<view class="astatus" :style="item.status==0||item.status==1?'':'background: #FF6161;'">
					{{item.status_text}}
				</view>
			</view>
			<view class="policynum">{{item.money}}</view>
			<view class="policytime">{{$t('wallet.name53')}}{{item.store_day}}{{$t('wallet.name52')}}</view>
			<view class="policy_btn" v-if="item.status==0||item.status==1">
				<view class="btn1" @click="btnbalance(item.id)">{{$t('wallet.name54')}}</view>
				<view class="btn2" @click="$fun.jump(`/pageA/wallet/withdrawal?id=8&storeLogid=${item.id}&money=${item.money}`)">{{$t('wallet.name1')}}
				</view>
			</view>
			<view class="policy_btn" v-if="item.status==0">
				<view class="agreement" v-if="item.contract_url==null">
					<checkbox style="transform:scale(0.6)" @click="isCh=!isCh" :checked="isCh" />
					<text style="color: #21a2f8;"
						@click="$fun.jump(`/pageC/signature/signature?src=${$baseUrl}zlf.jpg`)">
						{{$t('wallet.name55')}}
					</text>
				</view>
				<view class="btn1" @click="" v-if="item.contract_url==null" @click="gocontract(item.id)">{{$t('wallet.name56')}}</view>
				<!-- #ifdef APP-PLUS -->
				<view class="btn1" @click="dowfile(item.contract_url)" v-else>{{$t('wallet.name57')}}</view>
				<!-- #endif -->
				<!-- #ifdef H5 -->
				<view class="btn1" @click="Download(item.contract_url)" v-else>{{$t('wallet.name58')}}</view>
				<!-- #endif -->
			</view>
		</view>
		<noneDate v-if="storeLog.length==0"></noneDate>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				storeLog: [],
				isCh: false
			}
		},
		onShow() {
			this.getstore()
		},
		onReady() {
			uni.setNavigationBarTitle({
				title: this.$t('wallet.name5')
			})
		},
		methods: {
			getstore() {
				this.$fun.ajax.post('butt/storeLog', {}).then(res => {
					this.storeLog = res.data
				})
			},
			dowfile(file) {
				console.log(this.$baseUrl + file)
				this.$fun.jump(`/pageC/contract/contract?url=${this.$baseUrl + file}`)
				// uni.downloadFile({
				// 	//需要预览的文件地址
				// 	url: this.$baseUrl + file,
				// 	success: (res) => {
				// 		if (res.statusCode === 200) {
				// 			let url = res.tempFilePath

				// 		}
				// 	}
				// })
			},
			//签订合同下载
			Download(file) {
				// #ifdef H5
				let url = this.$baseUrl + file
				uni.setClipboardData({
					data: this.$baseUrl + file,
					success: function() {
						console.log('success'); //调用方法成功
					}
				})
				console.log(url);
				var oA = document.createElement("a");
				oA.download = ''; // 设置下载的文件名，默认是'下载'
				oA.target = "_blank"
				oA.href = url; //临时路径再保存到本地
				document.body.appendChild(oA);
				oA.click();
				oA.remove(); // 下载之后把创建的元素删除
				// #endif
				//下载文档
				// #ifdef APP-PLUS
				uni.downloadFile({
					url: file, //下载地址接口返回
					success: (data) => {
						if (data.statusCode === 200) {
							//文件保存到本地
							uni.saveFile({
								tempFilePath: data.tempFilePath, //临时路径
								success: function(res) {
									uni.showToast({
										icon: 'none',
										mask: true,
										title: this.$t('wallet.name59')+'：' + res.savedFilePath, //保存路径
										duration: 3000,
									});
									setTimeout(() => {
										//打开文档查看
										uni.openDocument({
											filePath: res.savedFilePath,
											success: function(res) {
												// console.log('打开文档成功');
											}
										});
									}, 3000)
								}
							});
						}
					},
					fail: (err) => {
						console.log(err);
						uni.showToast({
							icon: 'none',
							mask: true,
							title: this.$t('wallet.name60'),
						});
					},
				});
				// #endif
			},
			gocontract(id) {
				let signimg = uni.getStorageSync('signimg')
				if (!this.isCh || signimg == '') {
					this.$fun.msg(this.$t('wallet.name61'));
					return
				}
				this.$fun.ajax.post('order/contract ', {
					type: 2,
					sign: signimg,
					ordersn: id
				}).then(res => {
					if (res.code == 1) {
						this.$fun.msg(res.msg)
						setTimeout(() => {
							uni.removeStorage({
								key: 'signimg'
							})
							this.getstore()
						}, 1000)
					} else {
						this.GetUserProgress()
					}
				})
			},
			// 查询当前认证进度
			async GetUserProgress() {
				uni.showLoading({
					title: '',
					mask: true
				})
				const res = await this.$fun.ajax.post('withdraw/isVerify', {})

				uni.hideLoading()
				if (res.code == 1) {

				} else {
					// 尚未提前传入，跳转提前传入实名信息
					this.$fun.msg(this.$t('wallet.name34'))
					this.$fun.jump('/pageA/authentication/authentication', 0, 1200)
				}
			},
			btnbalance(id) {
				let _this = this
				uni.showModal({
					title: this.$t('wallet.name62'),
					success: function(res) {
						if (res.confirm) {
							console.log('用户点击确定');
							_this.$fun.ajax.post('butt/transferMoney', {
								id: id,
							}).then(res => {
								if (res.code == 1) {
									_this.$fun.msg(res.msg)
									_this.getstore()
								}
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				})

			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #F5F1EE;
	}

	.policy {
		width: 690rpx;
		// height: 282rpx;
		background: #FFFFFF;
		border-radius: 24rpx;
		margin: 30rpx auto 0;
		padding: 30rpx;

		&_top {
			font-weight: 400;
			font-size: 24rpx;
			color: #999999;
			display: flex;
			justify-content: space-between;
			align-items: center;

			image {
				width: 74rpx;
				height: 32rpx;
			}

			.astatus {
				width: 74rpx;
				height: 32rpx;
				background: #5BBE73;
				border-radius: 4rpx;
				font-weight: 500;
				font-size: 18rpx;
				color: #FFFFFF;
				line-height: 32rpx;
				text-align: center;
			}
		}

		.policynum {
			font-weight: 500;
			font-size: 48rpx;
			color: #333333;
		}

		.policytime {
			font-weight: 500;
			font-size: 28rpx;
			color: #333333;
		}

		&_btn {
			display: flex;
			justify-content: flex-end;
			margin-top: 30rpx;

			.btn1 {
				width: 184rpx;
				height: 72rpx;
				background: #FFFFFF;
				border-radius: 36rpx;
				border: 2rpx solid #5990FF;
				font-weight: 500;
				font-size: 28rpx;
				color: #5990FF;
				line-height: 72rpx;
				text-align: center;
			}

			.btn2 {
				width: 184rpx;
				height: 72rpx;
				background: #5990FF;
				border-radius: 36rpx;
				font-weight: 500;
				font-size: 28rpx;
				color: #FFFFFF;
				line-height: 72rpx;
				text-align: center;
				margin-left: 30rpx;
			}
		}
	}

	.agreement {
		// position: absolute;
		// top: -60rpx;
		// left: 50%;
		// transform: translateX(-50%);
		text-align: center;
		font-size: 24rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		color: #FFFFFF;
		line-height: 28rpx;
		padding: 10rpx;
	}
</style>